﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.ServiceModel;

namespace Test3_Server
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        ServiceHost host = null;
        private void button1_Click(object sender, EventArgs e)
        {
            host = new ServiceHost(typeof(Service1));

            NetTcpBinding tcpBinding = new NetTcpBinding();
            string address = "net.tcp://localhost:1111/test2";
            host.AddServiceEndpoint(typeof(Test2_ServiceLib.IService), tcpBinding, address);
            host.Opened += delegate { label1.Text = "服务已启动"; };
            host.Open();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (host.State != CommunicationState.Closed) {
                host.Close();
                label1.Text = "服务已关闭";
            }
        }
    }
}
